<template>
	<view class="histroyVistor-container">
		<view class="searchBar">
			<view class="searchBarTop">
				<view class="searchBarT-L">
					<text class="iconfont icon-icon-test12"></text>
					<input type="text" @input="inputVisitorName" v-model:value="visitorVo.visitorName" placeholder="搜索访客姓名"/>
					<text class="iconfont icon-icon-test44" v-if="clearInput" @click="clearInputContext"></text>
				</view>
				<view class="searchBarT-R">
					<text class="iconfont icon-yuyue"></text>
					<uni-datetime-picker 
						v-if="picker"
						class="picker"
						:clear-icon="true"
						v-model="range"
						type="daterange"
						returnType="string"
						@change="pickerDateRange">
						筛选日期
					</uni-datetime-picker>
					<text v-if="clear" @click="removeDate">清除选择</text>
				</view>
			</view>
			<view class="searchBarBottom">
				
			</view>
		</view>
		<scroll-view
			scroll-y="true" 
			class="scroll-Y"
			:style="{height:cssheight}"
			lower-threshold="50"
			@scrolltolower="scrollToLower">
			<view class="item" v-for="(item,index) in list" :key="item.visitorSignkey">
				<view class="itemTop">
					<view class="itemT-L">
						<text class="iconfont icon-manglu"></text>
						访客：{{item.visitorName}}
					</view>
					<view class="itemT-R">
						<text class="iconfont icon-keyuyue"></text>
						{{item.createTime | formateDate}}
					</view>
				</view>
				<view class="itemBottom">
					<view class="phone">
						<text class="iconfont icon-icon-test24"></text>
						联系电话：{{item.visitorPhone}}
					</view>
					<view class="appointment">
						<text class="iconfont icon-icon-test22"></text>
						预约时间：{{item.appointment}}
					</view>
					<view class="time">
						<text class="iconfont icon-icon-test5"></text>
						来访时间：{{item.visiting}}
					</view>
				</view>
			</view>
			<view class="noData" v-if="noDataShow">
				-- 已经没有数据了 --
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				visitorVo:{
					visitorName: '',
					beginDate: '',
					endDate: '',
				},
				current: 1,
				limit: 8,
				list: [],
				total: 0,
				pages: 0,
				userInfo:{},
				range: [],
				clear: false,
				picker: true,
				clearInput: false,
				cssheight:'',
				noDataShow: false
			}
		},		
		onReady() {
			var _this = this
			var css = ''
			uni.getSystemInfo({
				success: (resu) => {
					const query = uni.createSelectorQuery()
					query.select('.scroll-Y').boundingClientRect()
					query.exec(function(res){
						_this.height = resu.windowHeight -res[0].top + 'px'
						// console.log(_this.height)
						css = _this.height
					})
				}
			})
			this.cssheight = css
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			scrollToLower(){
				this.getPageList(this.current += 1)
			},
			clearInputContext(){
				this.clearInput = false
				this.visitorVo.visitorName = ''
				this.list = []
				this.getPageList()
			},
			inputVisitorName(){
				this.list = []
				this.clearInput = true
				// console.log(this.visitorVo)
				this.getPageList()
			},
			pickerDateRange(e){
				this.list = []
				this.picker = false
				this.clear = true
				this.visitorVo.beginDate = e[0]
				this.visitorVo.endDate = e[1]
				this.getPageList()
			},
			removeDate(){
				this.picker = true
				this.clear = false
				this.range = []
				this.visitorVo.beginDate = undefined
				this.visitorVo.endDate = undefined
				this.list = []
				this.getPageList()
			},
			//获得访客列表
			getPageList(page = 1){
				this.current = page
				this.$myReq({
					url: `/owner/visitor/visitorPageList/${this.userInfo.signKey}/${this.current}/${this.limit}`,
					method: 'post',
					data: this.visitorVo
				})
				.then((res) => {
					// console.log(res)
					this.list = [...this.list,...res.data.records]
					this.total = res.data.total
					this.pages = res.data.pages
					this.current = res.data.current
					if(res.data.records.length < 8){
						this.noDataShow = true
					}
				})
				.catch((err) => {
					console.log(err)
				})
			},
			//获得用户信息
			getUserInfo(){
				const token = uni.getStorageSync("userToken")
				// console.log(token)
				this.$myReq({
					url: '/owner/login/loginUserInfo/' + token,
					method:'GET'
				})
				.then((res) => {
					// console.log(res)
					this.userInfo = res.data
					this.getPageList()
				})
			}
		}
	}
</script>

<style lang="scss">
	.searchBar{
		// border: 1rpx solid red;
		background-color: #FFFFFF;
		padding: 0rpx 45rpx 5rpx 45rpx;
		.searchBarTop{
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			height: 100rpx;
			align-items: center;
			// border: 1px solid blue;
			.searchBarT-L{
				display: flex;
				flex: wrap;
				background-color: #f6f6f6;
				height: 70rpx;
				border-radius: 35rpx;
				width: 400rpx;
				text{
					display: inline-block;
					font-size: 40rpx;
					height: 70rpx;
					width: 70rpx;
					text-align: center;
					line-height: 70rpx;
					// border: 1px solid green;
				}
				input{
					font-size: 30rpx;
					height: 70rpx;
					line-height: 70rpx;
					width: 280rpx;
					// border: 1px solid green;
				}
				// border:1px solid black;
			}
			.searchBarT-R{
				height: 60rpx;
				width: 220rpx;
				border-radius: 30rpx;
				text-align: center;
				display: flex;
				justify-content: center;				
				.picker{
					// border: 1px solid red;
					line-height: 60rpx;
				}
				text{
					line-height: 60rpx;
					// border: 1px solid red;
				}
				text:nth-child(1){
					margin-right: 10rpx;
				}
				border: 1px solid #7c7c7c;
			}
		}
	}
	.scroll-Y{
		background-color: #f6f6f6;
		padding: 30rpx 30rpx 0rpx 30rpx;
		.item{		
			background-color: #FFFFFF;
			border-radius: 30rpx;
			width: 690rpx;
			margin-bottom: 20rpx;
			.itemTop{
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				padding: 30rpx 30rpx 10rpx 30rpx;
				.itemT-L{
					text{
						margin-right: 10rpx;
					}
					font-size: 35rpx;
					height: 80rpx;
					line-height: 80rpx;
				}
				.itemT-R{
					text{
						margin-right: 10rpx;
					}
					height: 80rpx;
					line-height: 80rpx;
				}
			}
			.itemBottom{
				padding: 20rpx 30rpx 10rpx 30rpx;
				view{
					margin-bottom: 10rpx;
					font-size: 30rpx;
					color: $main-garyB;
				}
			}
		}
		.noData{
			// border: 1px solid red;
			text-align: center;
			line-height: 100rpx;
			color: $main-garyB;
			height: 100rpx;
			width: 690rpx;
		}
	}
</style>
